import { message } from "antd";
import { useEffect } from "react";
import { useDispatch } from "react-redux";
import { getAllClassify } from "../../http/classify";
import { getAllContent } from "../../http/content";
import { homeActions } from "./home.slice";

export const useInitData = ()=>{
    const dispatch = useDispatch();
    // 获取所有内容
    useEffect(() => {
      getAllContent().then((data) => {
        dispatch(homeActions.setContent(data))
      }).catch(()=>{
        message.error("内容获取失败")
      });
  
      getAllClassify().then((data)=>{
        dispatch(homeActions.setClassify(data));
      }).catch(()=>{
        message.error("内容获取失败")
      });
    }, [dispatch]);
}